import 'package:flutter/material.dart';

// 类型定义
class GoodsItem {
  GoodsItem({
    required this.goodsNo,
    required this.goodsPrice,
    required this.goodsName,
    required this.goodsBrand,
  });
  final String goodsNo, goodsPrice, goodsName, goodsBrand;
}

// 角色分类
class GoodsManageModel extends ChangeNotifier {
  ///商品列表
  List<GoodsItem> goodsList = [];

  ///入库数量
  int addNum = 0;

  ///出库数量
  int reduce = 0;

  ///商品数量
  String goodsCount() => goodsList.length.toString();

  ///商品入库
  void add(GoodsItem goodsItem) {
    goodsList.add(goodsItem);
    addNum++;
    notifyListeners();
  }

  ///商品出库
  void reduceGoods(String goodsNo) {
    int index =
        goodsList.indexWhere((element) => element.goodsNo == goodsNo, 0);
    if (index == -1) return;
    goodsList.removeAt(index);
    reduce++;
    debugPrint(goodsList.toString());
    notifyListeners();
  }

  List<GoodsItem> findGoods(String goodsNo) {
    List<GoodsItem> filterList = goodsList
        .where((e) => (e.goodsName + e.goodsBrand + e.goodsNo + e.goodsPrice)
            .contains(goodsNo))
        .toList();

    return filterList;
  }
}
